$(document).ready(function () {
    var bid = getTid().bid;
    var typeName = getTid().typeName;
    $.get("type/showType", function (rs) {
        var types = rs.result;
        for (var i = 0; i < types.length; i++){
            if (types[i].typeName == typeName){
                $("<li class='layui-nav-item layui-this'>" +
                    "<a href='caty.html?tid=" + types[i].tid + "'>" + types[i].typeName +
                    "</a></li>").appendTo("#type");
                $("<a><cite> / " + types[i].typeName + "</cite></a>").appendTo("#ti");
                $("#ty").append("<a href=\"caty.html?tid=" + types[i].tid +"\">" + typeName + "</a>");
                $.get("blog/showBy", {"tid":types[i].tid}, function (rs) {
                    var blogs = rs.result;
                    for (var i = 0; i < blogs.length; i++){
                        $("<div class=\"layui-col-md4\">" +
                            "<div class=\"layui-card\">" +
                            "<a href='detail.html?bid=" + blogs[i].blogid +  "&type=" + blogs[i].typeName + "'>" +
                            "<img src='./static/images/list_img.png' />" +
                            // "<img src='../images/list_img.png' />" +
                            "<p>dhsuaidausd</p>" +
                            "<p>" + blogs[i].title + "</p>" +
                            "</a>" +
                            "</div>" +
                            "</div>").appendTo("#recommend");
                    }
                });
            }else {
                $("<li class='layui-nav-item'>" +
                    "<a href='caty.html?tid=" + types[i].tid + "'>" + types[i].typeName +
                    "</a></li>").appendTo("#type");
            }
        }
    });
    $.get("blog/showText", {"blogid": bid}, function (rs) {
        var blog = rs.result;
        $("<p>" + blog.title + "</p>\n" +
            "<div class=\"layui-row stat\">\n" +
            "<div class=\"layui-col-md3 layui-col-xs12\">发布时间：<em>" + blog.posttime + "</em></div>\n" +
            "<div class=\"layui-col-md2 layui-col-xs6\">分类：<a href=\"caty.html?type=" + blog.typeName + "\">" + blog.typeName + "</a></div>\n" +
            "<div class=\"layui-col-md2 layui-col-xs6\">作者：<a href=\"javascript:;\">" + blog.author + "</a></div>\n" +
            "<div class=\"layui-col-md5 layui-col-xs12\">\n" +
            "<div class=\"layui-row\">\n" +
            "<div class=\"layui-col-md6 layui-col-xs6\">\n" +
            "<i class=\"layui-icon layui-icon-read\"></i>\n" +
            "<em>" + blog.clicknumber + "次阅读</em>\n" +
            "</div>\n" +
            "</div>\n" +
            "</div>\n" +
            "</div>").appendTo("#title");
        $("<pre class=\"prettyprint lang-cs\">" + blog.detail + "</pre>").appendTo("#content");

    });

    $.get("blog/showByDesc", function (rs) {
        var blogs = rs.result;
        for (var i = 0;i < blogs.length; i++){
            $("<tr>" +
                "<td><a href='detail.html?bid=" + blogs[i].blogid +  "&type=" + blogs[i].typeName + "'>" + blogs[i].title + "</a></td>" +
                "</tr>").appendTo("#desc");
        }
    });



});
function getTid() {
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return decodeURIComponent(r[2]);
        return null; //返回参数值
    }
    var bid = getUrlParam("bid");
    var typeName = getUrlParam("type");
    return { bid: bid, typeName: typeName };
}